﻿using Vin.Tool.AspNetCore.Singleton;
using Vin.Tool.Core.NetCategory;

namespace Vin.Tool.Domain.SystemModel;

public class ApiResult
{
    /// <summary>
    /// 状态码
    /// </summary>
    public int Code { get; set; }

    /// <summary>
    /// 消息
    /// </summary>
    public string? Msg { get; set; }

    /// <summary>
    /// 数据
    /// </summary>
    public object? Data { get; set; }

    /// <summary>
    /// 总数
    /// </summary>
    public int Total { get; set; }

    /// <summary>
    /// 请求Id
    /// </summary>
    public string? RequestId { get; set; }

    public ApiResult(int code, string? msg)
    {
        this.Code = code;
        this.Msg = msg;
        RequestId = VinApp.HttpContextOrNull?.GetRequestId();
    }

    public ApiResult(int code, string? msg, object? data, int total = 0)
    {
        this.Code = code;
        this.Msg = msg;
        this.Data = data;
        this.Total = total;
        RequestId = VinApp.HttpContextOrNull?.GetRequestId();
    }
}

public class ApiResult<T> : ApiResult
{
    public new T? Data { get; set; }

    public ApiResult(int code, string? msg) : base(code, msg)
    {
    }

    public ApiResult(int code, string? msg, T? data, int total = 0) : base(code, msg, data, total)
    {
    }
}